package com.htht.smartschool.action.maillist;

import java.util.List;

import com.htht.smartschool.action.baseaction.BaseAction;
import com.htht.smartschool.common.model.ParamData;
import com.htht.smartschool.common.servlet.DataContainer;
import com.htht.smartschool.model.maillist.MailData;
import com.htht.smartschool.model.maillist.MessagePersons;
import com.htht.smartschool.model.maillist.StudentUserMaillist;
import com.htht.smartschool.model.maillist.TMaillist;
import com.htht.smartschool.service.maillist.MaillistService;
import com.htht.smartschool.util.system.GsonUtils;

public class MaillistAction extends BaseAction{

	@Override
	public boolean processData(DataContainer obj, ParamData pd) {
		boolean flag = false;
		MaillistService maillistService = new MaillistService();
		TMaillist maillist = (TMaillist) GsonUtils.getInstance().fromJson(pd.getData(), TMaillist.class);
		if(pd.getCmd().equalsIgnoreCase("getMaillistByClasscode")){
			List<MailData> list = maillistService.getMaillistByClasscode(maillist);
			if(list.size() > 0){
				flag = true;
				obj.setData(list);
			}else{
				obj.setData("查无数据！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getStudentMailList")){
			StudentUserMaillist studentusermaillist = (StudentUserMaillist) GsonUtils.getInstance().fromJson(
					pd.getData(), StudentUserMaillist.class);
			List<MailData> teacher = maillistService.getStudentMailList(studentusermaillist.getClasscode());
			if (teacher.size()>0) {
				flag = true;
				obj.setData(teacher);
			} else {
				obj.setData("查无数据！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getAllTeacherMailList")){
			List<MailData> teacher = maillistService.getAllTeacherMailList(maillist.getTeachercode());
			if (teacher.size()>0) {
				flag = true;
				obj.setData(teacher);
			} else {
				obj.setData("查无数据！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getMessagePersons")){
			MessagePersons teacher = maillistService.getMessagePersons(maillist.getTeachercode());
			if (teacher.getClasses().size() > 0 || teacher.getPersons().size() > 0) {
				flag = true;
				obj.setData(teacher);
			} else {
				obj.setData("查无数据！");
			}
		}
		return flag;
	}

}
